﻿import request from '/@/utils/request';
import other from '/@/utils/other';
import { AxiosResponse } from 'axios';
import {
  ISysHrStaffNeedRequestBill,
  ISysHrStaffNeedRequestBillView,
  ISysHrStaffNeedRequestBillVm
} from '/@/views/hr/syshrstaffneedrequestbill/api/interface';
import { IResult } from '/@/types/common';

interface ISysHrStaffNeedRequestBillApi {
  search(data: object): Promise<AxiosResponse<ISysHrStaffNeedRequestBillView[]>>;

  get(id: string | number): Promise<AxiosResponse<ISysHrStaffNeedRequestBillVm>>;

  add(data: ISysHrStaffNeedRequestBillVm): Promise<AxiosResponse<ISysHrStaffNeedRequestBill>>;

  edit(data: ISysHrStaffNeedRequestBillVm): Promise<AxiosResponse<ISysHrStaffNeedRequestBill>>;

  batchEdit(data: object): Promise<AxiosResponse>;

  delete(ids: (string | number)[]): Promise<AxiosResponse<number>>;

  export(data: object): Promise<void>;

  exportById(ids: (string | number)[]): Promise<void>;

  import(data: object): Promise<AxiosResponse<number>>;

  approve(data: object, tag: string): Promise<AxiosResponse<any, any>>;

  getBillCode(): Promise<IResult<string>>;

}

function SysHrStaffNeedRequestBillApi(): ISysHrStaffNeedRequestBillApi {
  return {
    async search(data: object): Promise<AxiosResponse<ISysHrStaffNeedRequestBillView[]>> {
      return await request({
        url: '/api/SysHrStaffNeedRequestBill/Search',
        method: 'post',
        data,
      });
    },
    async get(id: string | number): Promise<AxiosResponse<ISysHrStaffNeedRequestBillVm>> {
      return await request({
        url: `/api/SysHrStaffNeedRequestBill/${id}`,
        method: 'get',
      });
    },
    async add(data: ISysHrStaffNeedRequestBillVm): Promise<AxiosResponse<ISysHrStaffNeedRequestBill>> {
      return await request({
        url: '/api/SysHrStaffNeedRequestBill/Add',
        method: 'post',
        data,
      });
    },
    async edit(data: ISysHrStaffNeedRequestBillVm): Promise<AxiosResponse<ISysHrStaffNeedRequestBill>> {
      return await request({
        url: '/api/SysHrStaffNeedRequestBill/Edit',
        method: 'put',
        data,
      });
    },
    async batchEdit(data: object): Promise<AxiosResponse> {
      return await request({
        url: '/api/SysHrStaffNeedRequestBill/batchEdit',
        method: 'post',
        data,
      });
    },
    async delete(ids: (string | number)[]): Promise<AxiosResponse<number>> {
      return await request({
        url: '/api/SysHrStaffNeedRequestBill/BatchDelete',
        method: 'post',
        data: ids,
      });
    },
    async export(data: object): Promise<void> {
      const response = await request<any, Blob>({
        responseType: 'blob',
        url: '/api/SysHrStaffNeedRequestBill/ExportExcel',
        method: 'post',
        data,
      });
      other.downloadFile(response);
    },
    async exportById(ids: (string | number)[]): Promise<void> {
      const response = await request<any, Blob>({
        responseType: 'blob',
        url: '/api/SysHrStaffNeedRequestBill/ExportExcelByIds',
        method: 'post',
        data: ids,
      });
      other.downloadFile(response);
    },
    async import(data: object): Promise<AxiosResponse<number>> {
      return await request({
        url: '/api/SysHrStaffNeedRequestBill/Import',
        method: 'post',
        data,
      });
    },
    async approve(data: object, tag: string) {
      return request({
        url: '/api/SysHrStaffNeedRequestBill/approve?tag=' + tag,
        method: 'post',
        data,
      });
    },
    async getBillCode(): Promise<IResult<string>> {
      return await request({
        url: '/api/SysHrStaffNeedRequestBill/PredictCode',
        method: 'get',
      });
    },
  };
}

export { SysHrStaffNeedRequestBillApi };

